package main.java.Thread;

import java.util.Scanner;

public class homework2 {
    public static void main(String[] args) {
        Account c1 = new Account(1);
        Account c2 = new Account(2);
        c1.start();
        c2.start();

    }
}

class Account extends Thread{
    static int money = 10000;
    Scanner s = new Scanner(System.in);
    int clientNum;

    public Account(int clientNum){
        this.clientNum = clientNum;
    }

    @Override
    public void run() {
        while (true){
            int i = s.nextInt();
            if(i == clientNum){
                withdraw();
            }
        }
    }

    public synchronized void withdraw(){
        if(money <= 0){
            System.out.println("余额不足");
        }else {
            System.out.println(Thread.currentThread().getName() + "取钱1000 , 余额: " + (money-=1000));

        }
    }
}
